﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Restaurant.Common;
using Restaurant.Model;
using Restaurant.Dao;
using DapperExtensions;
using Restaurant.Model.ExModel;

namespace Restaurant.Business
{
    public class FoodBusiness
    {
        FoodTypeDao foodTypeDao = new FoodTypeDao();
        FoodDao FoodDao = new FoodDao();

        /// <summary>
        /// 获取分类关联菜品
        /// </summary>
        /// <param name="subId"></param>
        /// <returns></returns>
        public async Task<OperationResult> GetAllFoodTypeAndFoodAsync(Guid subId)
        {
            var tModel = await foodTypeDao.GetAllExAsync(subId);

            if (tModel == null)
                return new OperationResult(OperationResultType.QueryNull, "暂无数据", null);

            return new OperationResult(OperationResultType.Success, "成功", tModel);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<OperationResult> AddModeExAsync(FoodType_Food_Ex model)
        {
            var r = await foodTypeDao.AddModeEx(model);

            if (null == r)
                return new OperationResult(OperationResultType.Error, "添加失败", null);

            return new OperationResult(OperationResultType.Success, "成功", r);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<OperationResult> DeleteAsync(long id)
        {
            //判断是否能删除


            //删除
            var r = await foodTypeDao.RemoveAsync(id);

            if (false == r)
                return new OperationResult(OperationResultType.Error, "删除失败", null);

            return new OperationResult(OperationResultType.Success, "成功", r);


        }
    }
}
